home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / shell / tsbgex / src / win / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  4.2 KB  |  202 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h> 
  4. #include <winb.h>
  5. #include <te.h>
  6. #include <fntb.h>
  7. #include <gui.h>
  8. #include <egb.h>
  9. #include <guidbg.h>
  10. #include "win.h"
  11.  
  12. void main()
  13. {
  14.     MMICTRL ctrl;
  15.     extern int APL_init();
  16.  
  17.     if (MMI_CallMessage(MMI_GetApliId(), GM_QUERYID, QM_KIND, 1) > NOERR)
  18.         return;
  19.  
  20.     ctrl.displayPage = SCREENAVAILABLE;
  21.     ctrl.mode = SCREENAVAILABLE;
  22.     ctrl.page0 = SCREENIGNORE;
  23.     ctrl.page1 = SCREENIGNORE;
  24.     ctrl.size = 0;
  25.     ctrl.ptr = NULL;
  26.     ctrl.asize = 0;
  27.     ctrl.aptr = NULL;
  28.     ctrl.white = 15;
  29.     ctrl.black = 8;
  30.     ctrl.gray = 7;
  31.     ctrl.xor = 7;
  32.     
  33.     if (MMI_Open(&ctrl) != NOERR){
  34.         MMI_Close();
  35.         return;
  36.     }
  37.     if (APL_init() != NOERR){
  38.         MMI_Close();
  39.         return;
  40.     }
  41.     MMI_ExecSystem();
  42.     MMI_Close();
  43. }
  44.  
  45. int aplid;
  46.  
  47. APL_init()
  48. {
  49.     extern int userFunc();
  50.     extern int init();
  51.     extern void setmode();
  52.  
  53.     aplid = MMI_GetApliId();
  54.     init();
  55.     setmode(TRUE);
  56.     MMI_SendMessage(MMI_GetBaseObj(), MM_SETEXEC, 1, userFunc) ;
  57.     MMI_CallMessage(aplid, GM_TITLE, (int)SERVER_TITLE, 0) ;
  58.     MMI_CallMessage(aplid, GM_SLEEP, 0, 0) ;
  59.     return NOERR ;
  60. }
  61.  
  62. extern int create(), delete(), map(), unmap(), update(), move(), lower();
  63. static int (*winfuncs[])() = {
  64.     create, delete, map, unmap, update, move, lower
  65. };
  66. struct list head = { NULL, NULL }, tail = { NULL, NULL };
  67.  
  68. userFunc(int apliId, int messId, int info, int data)
  69. {
  70.     int    ret;
  71.     extern void terminate(), setmode();
  72.  
  73.     ret = ILLEGAL_FUNCTION ;
  74.  
  75.     switch (messId){
  76.         case GM_EXECUSER:
  77.             if (info == 0)
  78.                 ret = MAGIC;
  79.             else
  80.                 ret = (int)winfuncs;
  81.             break;
  82.         case GM_POSTSCRCHG:
  83.             setmode(FALSE);
  84.             ret = NOERR;
  85.             break;
  86.         case GM_QUIT:
  87.             terminate();
  88.             MMI_SetHaltFlag(TRUE);
  89.             ret = NOERR;
  90.             break;
  91.         case GM_PURGE:
  92.         case GM_ENVIRONMENT:
  93.         case GM_SHOW:
  94.         case GM_ERASE: 
  95.         case GM_UPDATE: 
  96.             ret = NOERR;
  97.             break;
  98.     }
  99.     return (ret);
  100. }
  101.  
  102. short vramseg;
  103. u_long vramoff;
  104. RESOLUTION mode = { 0, 0, 0, 0, 0, 0, };
  105. int own = FALSE;
  106. int fbxmax, pixelsize;
  107. void (*fbread)(), (*fbwrite)(), (*blkcpy)();
  108.  
  109. void setmode(int init)
  110. {
  111.     int owner;
  112.     char *title;
  113.     SCRNDATA screen;
  114.     extern int modecmp();
  115.     extern void setup();
  116.  
  117.     owner = MMI_CallMessage(aplid, GM_QUERYID, QM_BACKPAGE, 0);
  118.     title = (char *)MMI_CallMessage(owner, GM_TITLE, (int)NULL, 0);
  119. #ifdef DEBUG
  120.     printf("WIN: BACKPAGE owner is %s\n", title);
  121. #endif
  122.     MMI_CallMessage(owner, GM_SCRNDATA, FALSE, (int)&screen);
  123. #ifdef DEBUG
  124.     printf("WIN: setmode: %d %d %d %d %d %d 0x%x 0x%x\n", screen.usedPage,
  125.         screen.page[1].vx, screen.page[1].vy, 
  126.         screen.page[1].dx, screen.page[1].dy, 
  127.         screen.page[1].pixel, screen.page[1].segment,
  128.         screen.page[1].offset);
  129. #endif
  130.     if (init){
  131.         if (strcmp(title, OWNER) == 0){
  132.             own = TRUE;
  133.             mode = screen.page[1];
  134.             setup(&screen.page[1]);
  135.         } else {
  136.             own = FALSE;
  137.         }
  138.         return;
  139.     }
  140.     if (own){
  141.         if (strcmp(title, OWNER) == 0){
  142.             if (modecmp(&mode, &screen.page[1]) != 0){
  143. #ifdef DEBUG
  144.                 printf("WIN: mode change\n");
  145. #endif
  146.                 mode = screen.page[1];
  147.                 setup(&screen.page[1]);
  148.             }
  149.         } else {
  150.             own = FALSE;
  151.         }
  152.     } else {
  153.         if (strcmp(title, OWNER) == 0){
  154.             own = TRUE;
  155.             setup(&mode);
  156.         }
  157.     }
  158. }
  159.  
  160. void setup(RESOLUTION *page1)
  161. {
  162.     struct window *p;
  163.     extern void fbread16(), fbwrite16(), blkcpy16();
  164.     extern void fbread4(), fbwrite4(), blkcpy4();
  165.  
  166. #ifdef DEBUG
  167.     printf("WIN: setup: %d %d %d %d %d 0x%x 0x%x\n",
  168.         page1->vx, page1->vy, page1->dx, page1->dy, page1->pixel, 
  169.         page1->segment, page1->offset);
  170. #endif
  171.     vramseg = page1->segment;
  172.     vramoff = (u_long)page1->offset;
  173.     fbxmax = page1->vx - 1;
  174.     if (page1->pixel == 16){        /* 15bit color */
  175.         fbread = fbread16;
  176.         fbwrite = fbwrite16;
  177.         blkcpy = blkcpy16;
  178.         pixelsize = 2;
  179.     } else if (page1->pixel == 4){    /* 4bit color */
  180.         fbread = fbread4;
  181.         fbwrite = fbwrite4;
  182.         blkcpy = blkcpy4;
  183.         pixelsize = 1;
  184.     } else 
  185.         return;
  186.     for (p=head.next; p->next != NULL; p=p->next)
  187.         p->mapped = FALSE;
  188. }
  189.  
  190. modecmp(RESOLUTION *a, RESOLUTION *b)
  191. {
  192.     return (memcmp(a, b, sizeof (RESOLUTION) - sizeof (short)));
  193. }
  194.  
  195. void terminate()
  196. {
  197.     struct window *p;
  198.  
  199.     for (p = head.next; p->next != NULL; p = p->next)
  200.         MMI_CallMessage(p->aplid, GM_EXECUSER, 0, 0);
  201. }
  202.